var varLink;
var varTarget;
var varOption;

function createRequestObject() {
	try {
		var myRequest = new XMLHttpRequest();
	}
	catch(error) {
		try {
			var myRequest = new ActiveXObject("MSXML2.XMLHTTP");
		}
		catch(error) {
			var myRequest = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	
	return myRequest;
}

function EvalScript(response)
{	
	if(response.indexOf("//<script>") != -1)
	{
		eval(response);
		return true;
	}
	return false;
}

function Load(varLink, varTarget)
{
	this.varLink = varLink;
	this.varTarget = varTarget;
	this.varOption = "";
	
	StartRequest();
}

function LoadWithJava(varLink, varTarget)
{
	this.varLink = varLink;
	this.varTarget = varTarget;
	this.varOption = "java";
	
	StartRequest();
}

function StartRequest()
{
	req = createRequestObject();
		
	if (req != null) 
	{
    	req.onreadystatechange = function() {GetRequest();};
    	req.open("GET", this.varLink, true);
    	req.send(null);
  	}
}

function AjaxPost(varLink, varParam, varTarget)
{
	this.varLink = varLink;
	this.varTarget = varTarget;
	
	req = createRequestObject();
	
	if (req != null) 
	{
    	req.onreadystatechange = function() {GetRequest();};
    	req.open("POST", varLink, true);
		
		req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      	req.setRequestHeader("Content-length", varParam.length);
      	req.setRequestHeader("Connection", "close");
      
    	req.send(varParam);
    	
  	}
}

function GetRequest()
{
	if(req.readyState == 1 || req.readyState == 2 || req.readyState == 3 || req.readyState == 4)
	{
		if(req.readyState == 1)
		{
			document.getElementById(varTarget).innerHTML = " <center><img src='./images/load.gif'></br> "+varLangLoadData+"<center>";
		}
		else if(req.readyState == 2)
		{
			document.getElementById(varTarget).innerHTML = " <center><img src='./images/load.gif'></br> "+varLangLoadData+"</center>";
		}
		else if(req.readyState == 3)
		{
			document.getElementById(varTarget).innerHTML =  " <center><img src='./images/load.gif'></br> "+varLangLoadData+"</center>";
		}
		else if(req.readyState == 4)
		{
			if (req.status == 200) 
			{ 
				if(this.varOption == "java")
				{
					var resp = req.responseText;
					if(EvalScript(resp))
					{
						document.getElementById(varTarget).innerHTML = "";
					}
					else
					{
						document.getElementById(varTarget).innerHTML = resp;
					}
				}
				else
				{
					document.getElementById(varTarget).innerHTML = req.responseText;
				}
    		} 
			else 
			{
      			document.getElementById(varTarget).innerHTML="Error:\n"+ req.status + "\n" +req.statusText;
				req = null;
    		}
		}
	}
}